package org.example.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.example.entity.DepartmentalStructure;
import org.example.entity.Emp;
import org.example.models.R;
import org.example.service.DepartmentalStructureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/salary/setup/disposition")
public class DepartmentalStructureController {
    @Autowired
    DepartmentalStructureService departmentalStructureService;
    @GetMapping()
    public R<Page<DepartmentalStructure>> page(
            @RequestParam(name="current",defaultValue = "1") int current,
            @RequestParam(name="size",defaultValue = "10") int size,
            @RequestParam(name="departmental",required = false) String departmental,
            @RequestParam(name="postsName",required = false) String postsName
    ){
        QueryWrapper<DepartmentalStructure> queryWrapper = new QueryWrapper<>();
        if(departmental != null){
            queryWrapper.lambda().like(DepartmentalStructure::getDepartmental,departmental);
        }
        if(postsName != null){
            queryWrapper.lambda().like(DepartmentalStructure::getPostsName,postsName);
        }

        Page<DepartmentalStructure> page = new Page<>(current, size);

        departmentalStructureService.page(page,queryWrapper);
        return R.success(page);
    }
    @GetMapping("/find")
    public R<List<DepartmentalStructure>> page(
            @RequestParam(name="departmental",required = false) String departmental,
            @RequestParam(name="postsName",required = false) String postsName

    ){
        QueryWrapper<DepartmentalStructure> queryWrapper = new QueryWrapper<>();
        if(departmental != null){
            queryWrapper.lambda().like(DepartmentalStructure::getDepartmental,departmental);
        }
        if(postsName != null){
            queryWrapper.lambda().like(DepartmentalStructure::getPostsName,postsName);
        }


        List<DepartmentalStructure> list = departmentalStructureService.list(queryWrapper);
        return R.success(list);
    }
    @PostMapping("/disposition")
    public R insert(@RequestBody DepartmentalStructure departmentalStructure){
        departmentalStructureService.insert(departmentalStructure);
        return R.success();
    }
    @PutMapping("/update")
    public R update(@RequestBody DepartmentalStructure departmentalStructure){
        departmentalStructureService.updateByPrimaryKeySelective(departmentalStructure);
        return R.success();
    }

//    @DeleteMapping("/{id}")
//    public R delete(@PathVariable("id") String id){
//        bankCardService.removeById(id);
//        return R.success();
//    }
}
